<?php

/*
 * контроллер отвечающий за редактирование информации о юзере
 */

class Control_UserRedactAction extends Control_Action{
    
    public function setArgs($args = null) {
        if (null != $args){
            $this->args = $args;
        }
        return $this;
    }
    public function setView($view) {
        if (null != $view){
            $this->view = $view;
        }
        return $this;
    }
    public function run() {
        $t = Model_File::getSTime();
        $id = $this->args['id'];
        if (Model_UserMapper::getCurrentUser($id)) {
            if (!isset($this->args['name'])) {
                $this->view->user = Model_UserMapper::getThisUser($this->args['id'], 'user');
                $this->view->setInnerTemplate('redactUser');
            } else {
                $this->args = Model_UserMapper::saveUser($this->args);
                $res = (!is_array($this->args)) ? "?control=user&$id" : "?control=userRedact&$id";
                $_SESSION['time']=  Model_File::getTime($t);
                $_SESSION['memory'] = memory_get_usage();
                header("location: http://petrovland.site50.net/$res");
            }
        } else {
            $_SESSION['memory'] = memory_get_usage();
            $_SESSION['time'] = Model_File::getTime($t);
            header("location: http://petrovland.site50.net");
        }
        
    }
}
